package com.atguigu.service.impl;

import com.atguigu.entity.system.SysRole;
import com.atguigu.mapper.SysRoleMapper;
import com.atguigu.mapper.SysUserRoleMapper;
import com.atguigu.service.SysRoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    @Override
    public PageInfo<SysRole> findByPage(Integer current, Integer limit, String roleName) {
        PageHelper.startPage(current, limit);

        List<SysRole> list = sysRoleMapper.findByPage(roleName);

        PageInfo<SysRole> sysRolePageInfo = new PageInfo<>(list);
        return sysRolePageInfo;
    }

    @Override
    public void submit(SysRole sysRole) {
        sysRoleMapper.submit(sysRole);
    }

    @Override
    public void update(SysRole sysRole) {
        sysRoleMapper.update(sysRole);
    }

    @Override
    public void remove(long roleId) {
        sysRoleMapper.remove(roleId);
    }

    @Override
    public Map<String,Object>  findAll(Long userId) {
        List<SysRole> roleList = sysRoleMapper.findAll();
        List<Long> roleIdList = sysUserRoleMapper.selectRoleIdByUserId(userId);
        Map<String,Object> map = new HashMap<>();
        map.put("roleList",roleList);
        map.put("userRoleList",roleIdList);
        return map;
    }
}
